/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2025. All rights reserved.
 */

import { createHash } from '@ohos/hvigor-common';

export class ValueEntry {
  private readonly _name: string;
  private readonly _value: TaskInputValue;
  private readonly _valueType: unknown;
  private _hash: string | undefined;

  constructor(name: string, value: TaskInputValue) {
    this._name = name;
    this._value = value;
    this._valueType = typeof value;
  }

  getName(): string {
    return this._name;
  }

  getValue(): TaskInputValue {
    return this._value;
  }

  getValueType(): unknown {
    return this._valueType;
  }

  getHash(): string {
    if (!this._hash) {
      this._hash = createHash().update(this._name).update(`${this._value}`).update(`${this._valueType}`).digest('hex');
    }
    return this._hash;
  }
}

export type TaskInputValue = number | string | boolean | string[] | number[] | boolean[];
